#include <iostream>
using namespace std;
#include <string>
#include <stdlib.h>
#include <cstring>

class Animal
{
public:
    Animal()
    {
        cout << "Animal()" << endl;
    }
    virtual ~Animal()
    {
        cout << "~Animal()" << endl;
    }

public:
    /*叫*/
    /*11.虚函数就是被virtual修饰的函数*/
    virtual void speak()
    {
        cout << "Animal::speak" << endl;
    }

    /*跑*/
    virtual void run()
    {
        cout << "Animal::run" << endl;
    }

private:
    int m_age;
};

class Cow : public Animal
{
public:
    /*叫*/
    void speak()
    {
        cout << "cow::speak mou mou mou" << endl;
    }

    /*跑*/
    void run()
    {
        cout << "cow::run mou mou mou" << endl;
    }

private:
    char m_color[24];
};

class Horse : public Animal
{
public:
    void speak()
    {
        cout << "horse::speak manbo manbo" << endl;
    }

    /*跑*/
    void run()
    {
        cout << "horse::run manbo manbo" << endl;
    }

private:
    /*马的品种*/
    string m_type;
};

class CowHorse : public Animal
{
public:
    CowHorse()
    {
        m_mortage = new char[32];
        memset(m_mortage,0,sizeof(char)*32);
        strcpy(m_mortage,"32000");
        cout << "CowHorse()" << endl;
    }
    ~CowHorse()
    {
        if(m_mortage != NULL)
        {
            delete m_mortage;
        }

        cout << "~CowHorse()" << endl;
    }

public:
    /*子类调用父类的成员函数*/
    void speak()
    {
        Animal::speak();
        cout << "CowHorse::speak 收到 好的 ok" << endl;
    }

    /*跑*/
    void run()
    {
        cout << "CowHorse::run 摆烂 摆烂 摆烂" << endl;
    }

private:
    int m_worktime;
    char * m_mortage;
};

/*甲方客户·*/
/*具有纯虚函数的类被称为抽象类*/
class customer
{
public:
    customer()
    {

    }
    ~customer()
    {

    }

public:
    /*扫码*/
    /*纯虚函数*/
    virtual void scanCode() = 0;
    /*打印小票*/
    virtual void printTicket() = 0;
private:
    int m_budget;
};


class JuankeCoder:public customer
{
public:
    void scanCode()
    {
        cout << "JuankeCoder::scanCode()" <<endl;
    }
    /*打印小票*/
    void printTicket()
    {
        cout << "JuankeCoder::printTicket()" <<endl;
    }

};


class Student
{
public:
    Student(int stuId)
    {
        m_stuId = stuId;
    }
    virtual void study()
    {
        cout << "study()" <<endl;
    }
public:
    int m_stuId;
};

class Worker
{
public:
    Worker(int salary)
    {
        m_salary = salary;
    }
    virtual void overWork()
    {
        cout << "overWork()" <<endl;
    }
public:
    int m_salary;
};

/*多继承*/
class underGraduate:public Student,public Worker
{
public:
    underGraduate(int stuId,int salary,int rent):Student(stuId),Worker(salary)
    {
        m_rent = rent;
    }

    void display()
    {
        cout <<" "<< Student::m_stuId <<" "<< m_salary <<" "<< m_rent <<endl;
    }

    void study()
    {
        cout << "underGraduate::study()" <<endl;
    }

    void overWork()
    {
        cout << "underGraduate::overWork()" <<endl;
    }

    void play()
    {
        cout << "underGraduate::play()" <<endl;
    }
public:
    int m_stuId;
    int m_rent;
};




int main()
{
#if 0
    Animal ani;
    cout << sizeof(ani) <<endl;
    ani.speak();
    ani.run();

    Cow cow;
    cout << sizeof(cow) <<endl;
    cow.speak();
    cow.run();

    Horse horse;
    horse.speak();
    horse.run();
    return 0;
#endif

#if 0
        /*10.多态的使用*/

        /*父类指针指向子类对象*/
        Animal *ani1 = new Cow;

        ani1->speak();

        ani1 = new Horse;

        ani1->speak();

        ani1 = new CowHorse;
        ani1->speak();
#endif

#if 0
    /*12.虚表*/
    CowHorse ch;

    cout << "111" << endl;
#endif

#if 0
    Animal * ani = new CowHorse;
    ani->speak();

    delete ani;
    cout << "111" << endl;
#endif

#if 0
    JuankeCoder coder;
    cout << " "<<endl;
#endif

#if 1
    underGraduate ug(43639,9500,1900);
    ug.display();
#endif
}
